//
//  MDataDetailLightViewController.m
//  Gunz
//
//  Created by Joggy on 16/8/25.
//  Copyright © 2016年 NUPT. All rights reserved.
//

#import "MDataDetailLightViewController.h"

@interface MDataDetailLightViewController ()<UITableViewDelegate, UITableViewDataSource> {
    
    UITableView *table;
    NSArray *data;
    
}

@end

@implementation MDataDetailLightViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self prepareForNav];
    [self prepareForLayout];
    
    data = [NSArray arrayWithContentsOfFile:_dataPath];
    
}

- (void)prepareForNav {
    [super prepareForNav];
    self.title = @"光线数据详情";
    //导航左按键
    UIImage *image = [UIImage imageNamed:@"all_back"];
    UIButton *leftBarButton = [UIButton buttonWithType:UIButtonTypeSystem];
    leftBarButton.frame = CGRectMake(0, 0, image.size.width, image.size.height);
    leftBarButton.layer.position = CGPointMake(22, 22);
    [leftBarButton setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [leftBarButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBarButton];
}

- (void)prepareForLayout {
    [super prepareForLayout];
    table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight - 64) style:UITableViewStylePlain];
    table.delegate = self;
    table.dataSource = self;
    table.backgroundColor = [UIColor clearColor];
    table.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 10)];
    table.tableFooterView = [[UIView alloc] init];
    table.showsVerticalScrollIndicator = false;
    table.separatorStyle = UITableViewCellSelectionStyleBlue;
    table.separatorColor = [UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1];
    [table registerClass:[UITableViewCell class] forCellReuseIdentifier:@"MDataDetailLightCell"];
    [self.view addSubview:table];
}

- (void)back {
    [self.navigationController popViewControllerAnimated:true];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:true];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 47;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return data.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MDataDetailLightCell"];
    cell.textLabel.text = data[indexPath.row];
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
